<template>
	<view class="content">
		<view class="login_title">
			密码验证
			<!-- <image src="/static/images/编组.png" mode="aspectFit"></image> -->
		</view>
		<view class="content_input">
			<input v-model="isChecked" type="text" placeholder="请输入" placeholder-class="pcs" />
		</view>
		<view class="login_btn">
			<button @click="handleBack" class="cancle">取消</button>
			<button class="confirm" open-type="getUserInfo" @click="handleLogin">确定</button>
		</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from "vue"
	import {
		onLoad
	} from "@dcloudio/uni-app"
	import request from '@/utils/request'
	import {
		loginService,
		adminLogin
	} from "../../api/user"
	import {
		toast
	} from "@/utils/common.js"
	import {
		useUserStore
	} from "../../stores"
	const userStore = useUserStore()
	// import {
	//     getSetting
	// } from "@dcloudio/uni-app"
	const isChecked = ref('')
	const type = ref('1')
    onLoad((options) => {
        console.log(222,options)
        type.value = options.type;
    });
	const login = () => {
		console.log(isChecked.value);
		// if (!isChecked.value) return;
		uni.showToast({
			title: '登录中...',
			icon: 'none'
		})
		uni.login({
			provider: 'weixin',
			success(res) {
				let data = {
					code: res.code
				}
				loginService(data).then(res => {
					// getStorageSync
					if (res.code == 200) {
						uni.setStorageSync('token', res.data)
						// getUser()
						uni.switchTab({
							url: '/pages/layout/layout'
						})
					}

				})
				uni.hideLoading()
			},
			fail() {
				uni.hideLoading();
			}
		});
	}
	// const getUserInfo = () => {
	//     let that = this;
	//     let p = this.getSetting();
	//     p.then(function(isAuth) {
	//         console.log('是否已经授权', isAuth);
	//         if (isAuth) {
	//             // console.log('用户信息，加密数据’，e);
	//             //eData 包括//微信头像//微信名称 还有加密的数据
	//             // let eData = JSON.parse(e.detail.rawData); //接下来就是访问接口.
	//             uni.request({
	//                 header: {
	//                     "content-type": 'application/x-www-form-urlencoded'
	//                 },
	//                 url: '/wxLogin', //你的接口地址,
	//                 method: 'POST', //接口类型,
	//                 // data: '，//接口需要的数据,
	//                 success: function(res) {
	//                     console.log(res);
	//                     if (res.data.Success) {
	//                         that.login(res.data); //将接口返回的数据保存在全局变量中
	//                         //登录成功跳转首页或者你想跳转的地方...
	//                         //注意:如果时导航页 请用uni.switchTab
	//                         // 其他页面建议使用uni.reLaunch
	//                     } else {
	//                         uni.showToast({
	//                             title: '授权登录失败!'

	//                         })
	//                     }
	//                 }
	//             })

	//         }
	//     })
	// }
	const handleBack = () => {
		uni.navigateBack()
	}
	const handleLogin = () => {
		if (!isChecked.value) {
			toast('请输入密码')
			return
		}
		adminLogin({
			id: userStore.user.id,
			pwd: isChecked.value
		}).then(res => {
			if (res.code == 200) {
				toast("登录成功")
				setTimeout(() => {
                    if(type.value =='1'){
                        uni.redirectTo({
                            url: "/pages/delete/delete"
                        })
                    }else {
                        uni.navigateTo({
                            url: '/pages/tosellrooms/tosellrooms'
                        })
                    }
				}, 2000)

			} else if (res.msg) {
				toast(res.msg)
			}
		}).catch((err) => {
			console.log(err)
			toast('登录失败')
		})
	}
</script>

<style lang="scss" scoped>
	pcs {
		font-size: 28rpx;
		color: rgba(202, 202, 202, 1);
		text-align: center;
	}

	.content {
		width: 568rpx;
		height: 315rpx;
		gap: 60rpx;
		padding: 60rpx 32rpx;
		border-radius: 30rpx;
		margin-top: 160rpx;
		margin-left: 60rpx;
		background-color: #fff;
		border: 1rpx solid rgba(187, 187, 187, 0.5);

		.login_title {
			position: relative;
			width: 568rpx;
			height: 39rpx;
			text-align: center;
			color: rgba(3, 19, 15, 1);
			font-size: 28rpx;
			margin-bottom: 60rpx;

			image {
				position: absolute;
				right: 10rpx;
				width: 26rpx;
				height: 26rpx;
			}
		}

		.content_input {
			width: 528rpx;
			height: 60rpx;
			gap: 10rpx;
			text-align: center;
			border-radius: 100rpx;
			padding: 9rpx 20rpx;
			margin-bottom: 60rpx;
			margin-bottom: 60rpx;
			border: 2rpx solid #CACACA;
		}

		.login_btn {
			display: flex;
			justify-content: space-between;
			align-items: center;
			width: 568rpx;
			height: 78rpx;
			margin-bottom: 60rpx;
			gap: 48rpx;

			button {
				width: 568rpx;
				height: 78rpx;
				font-size: 28rpx;
				gap: 10rpx;
				border-radius: 100rpx;
			}

			.cancle {
				color: rgba(187, 187, 187, 1);
				background-color: rgba(187, 187, 187, 0.1);
				border: 2rpx solid rgba(187, 187, 187, 0.1);
			}

			.confirm {
				background-color: rgba(79, 129, 240, 1);
				color: rgba(255, 255, 255, 1);
				border: 2rpx solid rgba(79, 129, 240, 1);
			}
		}

	}
</style>